/**
 * 初始化主页
 */
$(function () {
    // 异步请求热门新闻数据
    $.ajax({
       type: 'get',
       url: 'http://127.0.0.1:8081/qiantai/home',
       data: {},
       success: function (data) {
            // console.log(data);
            $("#news1").html("<a href=\"#\" title='"+data.newsList[0].title+"' onclick=\"findById("+data.newsList[0].id+",'/html/news_details.html')\"><p class='news'>"+data.newsList[0].title+"</p></a>");
            $("#news2").html("<a href=\"#\" title='"+data.newsList[1].title+"' onclick=\"findById("+data.newsList[1].id+",'/html/news_details.html')\"><p class='news'>"+data.newsList[1].title+"</p></a>");
           for (let i = 0; i < 3; i++) {
               var product = data.productList[i];
               let num = 1+i;
               let products = "<li class=\"item"+num+"\">\n" +
                   "                                    <a href=\"#\" class='news'  onclick=\"findById('"+product.id+"','/html/product_details.html')\">\n" +
                   "                                        <img src='"+product.img+"' />\n" +
                   "                                    </a>\n" +
                   "                                </li>";
               $("#prducts").append(products);
           }
            return false;
       },
        error: function () {
            layui.layer.msg('请求接口异常,请刷新重试！',{icon:0,time:1300});
            return false;
        }
    });
})